Triple Transfer JSON

Source: Internet
Author: User

   Public classTriple { PublicTriple (string_s,string_p,string_o) {             This. _s =_s;  This. _p =_p;  This. _o =_o; }         Public string_s {Set;Get; }  Public string_p {Set;Get; }  Public string_o {Set;Get; } }

function

Static voidTripletransferjson (string_s,refJobject obj) {             if(List = =NULL|| List. Count = =0)return; List<Triple> sublist = list. Where (A = a._s = =_s).            ToList (); Obj. ADD ("PrimaryKey", _s); //Get Property Countdictionary<string,int> dt =Getpropertycount (sublist); foreach(varIteminchsublist) {                if(Item._o.startswith ("\"") && dt[item._p] = =1) obj.                ADD (item._p, item._o); if(Item._o.startswith ("\"") && Dt[item._p] >1)                {                    if(obj. ContainsKey (Item._p)) ((Jarray) obj[item._p]).                    ADD (Item._o); Elseobj. ADD (Item._p,NewJarray (item._o)); } sublist= list. Where (A = a._s = =item._o).                ToList (); Jobject jobj=NewJobject (); Tripletransferjson (Item._o,refjobj); if(Dt[item._p] = =1&&!item._o.startswith ("\"") ) obj.                ADD (item._p, jobj); if(Dt[item._p] >1&&!item._o.startswith ("\""))                {                    if(obj. ContainsKey (Item._p)) ((Jarray) obj[item._p]).                    ADD (Jobj); Elseobj. ADD (Item._p,NewJarray (jobj)); }            }        }        Staticdictionary<string,int> Getpropertycount (list<triple>list) {            if(List = =NULL|| List. Count = =0)return NULL; Dictionary<string,int> dt =Newdictionary<string,int>(); varPC = fromPinchList group p by p._p to GSelect New{property = G.key, Count =g.count ()}; foreach(varIteminchpc) {dt.            ADD (Item.property, Item.count); }            returnDT; }

Test data

List. ADD (NewTriple ("Http://knowledge.microsoft.com/sfesfesfefs","Type.object.name","\ "Wangshuang")); List. ADD (NewTriple ("Http://knowledge.microsoft.com/sfesfesfefs","Type.object.type","\ "People.person")); List. ADD (NewTriple ("Http://knowledge.microsoft.com/sfesfesfefs","Type.object.gender","\ "Female")); List. ADD (NewTriple ("Http://knowledge.microsoft.com/sfesfesfefs","Type.object.name","\ "Sky")); List. ADD (NewTriple ("Http://knowledge.microsoft.com/sfesfesfefs","Type.object.image","HTTP://KNOWLEDGE.MICROSOFT.COM/SFESFESFEFD")); List. ADD (NewTriple ("Http://knowledge.microsoft.com/sfesfesfefs","Type.object.image","HTTP://KNOWLEDGE.MICROSOFT.COM/SFESFESFEF3")); List. ADD (NewTriple ("HTTP://KNOWLEDGE.MICROSOFT.COM/SFESFESFEFD","Type.object.type","\ "Common.image")); List. ADD (NewTriple ("HTTP://KNOWLEDGE.MICROSOFT.COM/SFESFESFEF3","Type.object.type","\ "Common.image")); List. ADD (NewTriple ("HTTP://KNOWLEDGE.MICROSOFT.COM/SFESFESFEFD","Type.image.uri","\ "Http://www.baidu.com")); List. ADD (NewTriple ("HTTP://KNOWLEDGE.MICROSOFT.COM/SFESFESFEF3","Type.image.uri","\ "Http://www.baidu.com")); Jobject obj=NewJobject (); Tripletransferjson ("Http://knowledge.microsoft.com/sfesfesfefs",refobj); stringJSON = obj. ToString ();

Test result

{  "PrimaryKey":"Http://knowledge.microsoft.com/sfesfesfefs",  "Type.object.name": [    "\ "Wangshuang",    "\ "Sky"  ],  "Type.object.type":"\ "People.person",  "Type.object.gender":"\ "Female",  "Type.object.image": [    {      "PrimaryKey":"HTTP://KNOWLEDGE.MICROSOFT.COM/SFESFESFEFD",      "Type.object.type":"\ "Common.image",      "Type.image.uri":"\ "Http://www.baidu.com"    },    {      "PrimaryKey":"HTTP://KNOWLEDGE.MICROSOFT.COM/SFESFESFEF3",      "Type.object.type":"\ "Common.image",      "Type.image.uri":"\ "Http://www.baidu.com"    }  ]}

Triple Transfer JSON

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.