BookmarkSubscribeRSS Feed
gizemetus
Fluorite | Level 6

this is my file .

 

I want to pars my file but  I can't determine the file path correctly.

 

my code is working properly

" sv ": {

    " totalData ": Toplam veri adedi,

    " total ": veriler veri adedi,

    " totalPage ": toplam sayfa adedi,

    " sayfa ": aktif sayfa numarası,

    " user ": firma kullanıcılarını ve yetkileri [

      {

        " id ": "kullanıcı id'si",

        " name ": "kullanıcı adı",

        " listOfManageCompanies ": yönetim kurulu yetkisi olan firmalar

        {

          " şirket ": [

            "FirmaAdı"

            ...

          ]

        },

        " listOfManageAreas ": site yönetimi yetkisi olan alanlar

        {

          " alan ": [

            "Tam Yetkili", (bütün alanlara ekleme yetkisi)

            "Şikayet Yönetimi", (Şikayet Yönetimi yetkisi)

            "Firma Raporu", (Firma Raporu taslağı yetkisi)

            "Sektör Raporu", (Sektör Raporu sunmak yetkisi)

          ]

        }

      },

 

filename cp temp ;
proc groovy classpath=cp;
add classpath="C:\Users\trsasadm\AppData\Local\Temp\Temp1_groovy_2.3.7.0_SAS_20141114161537.zip\eclipse\plugins\groovy_2.3.7.0_SAS_20141114161537\groovy-all.jar";
submit parseonly;
import groovy.json.JsonSlurper
class MyJsonParser {
    def parseFile(path) {
     def jsonFile = new File("F:\\Sikayetvar_pdt.txt")
    def jsonText = jsonFile.getText()
    def InputJSON = new JsonSlurper().parseText(jsonText)
        def accounts = {}
        InputJSON.sv.each{
  accounts << [
  totalData : it.totalData
         ]
          
        }
        return accounts
    }
}
endsubmit;
submit parseonly;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
public class MyJsonParser4Sas {
    public String filename = "F:\\Sikayetvar_pdt.txt";
    public void init() {
        MyJsonParser myParser = new MyJsonParser();
        accounts = myParser.parseFile(filename);
        iter = accounts.iterator();
    }
     public boolean hasNext() {
        return iter.hasNext();
    }
    public void getNext() {
        account = ((LinkedHashMap) (iter.next()));
    }
     public String getString(String k) {
        return account.get(k);
    }
     protected ArrayList accounts;
    protected Iterator iter;
    protected LinkedHashMap account;
}
endsubmit;
quit;
options set=classpath "%sysfunc(pathname(cp,f))";
data accounts;
   attrib i  label="i"      length=  8
         totalData:      label="totalData" length=$  50
     ;
 dcl javaobj accounts("MyJsonParser4Sas");
   accounts.exceptiondescribe(1);
   accounts.setStringField("filename", "C:\\foo.json");
   accounts.callVoidMethod("init");
   accounts.callBooleanMethod("hasNext",rc);
   do i=1 by 1 while(rc);
      accounts.callVoidMethod("getNext");
    accounts.callStringMethod("getString", "totalData", totalData);
     output;
   accounts.callBooleanMethod("hasNext",rc);
   end;
 
   drop rc;
run;

 

 

 

filename cp temp ; proc groovy classpath=cp; add classpath="C:\Users\trsasadm\AppData\Local\Temp\Temp1_groovy_2.3.7.0_SAS_20141114161537.zip\eclipse\plugins\groovy_2.3.7.0_SAS_20141114161537\groovy-all.jar"; submit parseonly; import groovy.json.JsonSlurper class MyJsonParser { def parseFile(path) { def jsonFile = new File("F:\\Sikayetvar_pdt.txt") def jsonText = jsonFile.getText() def InputJSON = new JsonSlurper().parseText(jsonText) def accounts = [] InputJSON.sv.each{ accounts << [ totalData : it.totalData ] } return accounts } } endsubmit; submit parseonly; import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedHashMap; public class MyJsonParser4Sas { public String filename = "F:\\Sikayetvar_pdt.txt"; public void init() { MyJsonParser myParser = new MyJsonParser(); accounts = myParser.parseFile(filename); iter = accounts.iterator(); } public boolean hasNext() { return iter.hasNext(); } public void getNext() { account = ((LinkedHashMap) (iter.next())); } public String getString(String k) { return account.get(k); } protected ArrayList accounts; protected Iterator iter; protected LinkedHashMap account; } endsubmit; quit; options set=classpath "%sysfunc(pathname(cp,f))"; data accounts; attrib i label="i" length= 8 totalData: label="totalData" length=$ 50 ; dcl javaobj accounts("MyJsonParser4Sas"); accounts.exceptiondescribe(1); accounts.setStringField("filename", "C:\\foo.json"); accounts.callVoidMethod("init"); accounts.callBooleanMethod("hasNext",rc); do i=1 by 1 while(rc); accounts.callVoidMethod("getNext"); accounts.callStringMethod("getString", "totalData", totalData); output; accounts.callBooleanMethod("hasNext",rc); end; drop rc; run;
 

 

1 REPLY 1
ChrisNZ
Tourmaline | Level 20

You point to a file several times.

Which part fails?

What message do you get?

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 440 views
  • 0 likes
  • 2 in conversation